package htsetup

import (
	"core/corerun"
	"core/corestruct"
	"core/db"
	"golang.org/x/net/context"
)

func DbSetup(ctx *corestruct.HttpContext) {
	var p = &dbSetup{
		ctx:   ctx,
		lpage: nil,
		lact:  nil,
	}
	p.Setup(ctx)
}

func MeueSetup(ctx *corestruct.HttpContext) {
	var p = &menuSetup{
		ctx:   ctx,
		lpage: nil,
		lmenu: nil,
	}
	p.Setup(ctx)
}

func AllSetup() {

	var ctx = &corestruct.HttpContext{
		Id: 0,
		Session: &corestruct.HttpSession{
			CrtUid:   1000,
			HtdeptId: 1000,
			HtplatId: 1000,
		},
		DB: db.DbMaster,
	}

	dbctx := context.WithValue(context.Background(), "MyContext", ctx)
	var db2 = db.DbMaster.WithContext(dbctx)
	ctx.DB = db2

	corerun.CoreDbSetup()
	corerun.CoreStructToDb(db2, "core")
	corerun.CoreStructToDb(db2, "ht")
	corerun.CoreActionToDb(ctx, "ht")

	DbSetup(ctx)
	MeueSetup(ctx)

}
